<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div onclick="onBridgeReady()">123</div>

</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
    function ajax() {


    }
    function onBridgeReady(){
        var token = "c33a94699b1e9e2553ff2a4d39459eac893e0149a932c92a71c69071e3c61ddd";
        $.ajax({
            url: '/api/my/pay/pay',
            type: 'post',
            // 设置的是请求参数
            data: { id: 7},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", token);
              },
            //headers:{'Accept': 'application/json','Authorization':"c33a94699b1e9e2553ff2a4d39459eac893e0149a932c92a71c69071e3c61ddd"},
            // 用于设置响应体的类型 注意 跟 data 参数没关系！！！
            dataType: 'json',
            success: function (res)  {
                console.log(res.data.appId)
                var data =  res.data;
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', {
                        "appId": data.appId,     //公众号名称，由商户传入
                        "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数
                        "nonceStr":data.nonceStr, //随机串
                        "package":data.package,
                        "signType":"MD5",         //微信签名方式：
                        "paySign":data.paySign //微信签名
                    },
                    function(res){
                        if(res.err_msg == "get_brand_wcpay_request:ok" ){
                            // 使用以上方式判断前端返回,微信团队郑重提示：
                            //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                        }
                    });
            }
        })

    }
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }
</script>
</html>